﻿Imports System.IO
Imports System.Environment
Imports System.Math

Public Class szerelobetolt
    Public kod As String = ""
    Private Sub szerelobetolt_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim f As New StreamReader("adatlapszerelo.txt")
        Dim db As Integer

        While Not f.EndOfStream
            CBszerelo.Items.Add(f.ReadLine)
            CBdatum.Items.Add(f.ReadLine)
            CBnev.Items.Add(f.ReadLine())
            CBkod.Items.Add(f.ReadLine())
            CBlakcim.Items.Add(f.ReadLine)
            CBtelefon.Items.Add(f.ReadLine)
            CBrendszam.Items.Add(f.ReadLine)
            CBtipus.Items.Add(f.ReadLine)

            db = f.ReadLine
            db *= 4
            For i As Integer = 1 To db
                f.ReadLine()
            Next
            f.ReadLine()
        End While
        f.Close()

        CBszerelo.SelectedIndex = 0
    End Sub

    Private Sub Bkilepes_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bkilepes.Click
        Close()
    End Sub

    Private Sub CBszerelo_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CBszerelo.SelectedIndexChanged
        Dim f As New StreamReader("adatlapszerelo.txt")
        Dim s As String
        Dim db As Integer
        RTBkiir.Text = ""

        TBosszeg.Text = ""
        TBosszido.Text = ""

        CBdatum.SelectedIndex = CBszerelo.SelectedIndex
        CBnev.SelectedIndex = CBszerelo.SelectedIndex
        CBkod.SelectedIndex = CBszerelo.SelectedIndex
        CBlakcim.SelectedIndex = CBszerelo.SelectedIndex
        CBtelefon.SelectedIndex = CBszerelo.SelectedIndex
        CBrendszam.SelectedIndex = CBszerelo.SelectedIndex
        CBtipus.SelectedIndex = CBszerelo.SelectedIndex


        f.ReadLine()
        f.ReadLine()
        f.ReadLine()
        s = f.ReadLine()
        While CBkod.SelectedItem <> s

            For i As Integer = 1 To 4
                f.ReadLine()
            Next
            db = f.ReadLine
            For i As Integer = 1 To ((db * 4) + 4)
                f.ReadLine()
            Next

            s = f.ReadLine()
        End While

        For i As Integer = 1 To 4
            f.ReadLine()
        Next

        db = f.ReadLine()
        Dim osszeg As Integer = 0
        Dim osszido As Integer = 0

        For i As Integer = 1 To db
            s = f.ReadLine
            Dim s1 As Integer = 0
            Dim s2 As Integer = 0
            Dim s3 As Integer = 0

            Select Case s
                Case "0"
                    s1 = f.ReadLine
                    s2 = f.ReadLine
                    s3 = f.ReadLine
                    RTBkiir.Text += "Munkaórák száma: " + s1.ToString + NewLine + "Szerelő: " + CBszerelo.SelectedItem.ToString + NewLine + "Óradíj: " + s3.ToString + " HUF" + NewLine + "-------------------------------------" + NewLine + "Összesen: " + (s1 * s3).ToString + "HUF" + NewLine + NewLine + NewLine
                    osszeg += s1 * s3
                    osszido += s1
                Case "1"
                    RTBkiir.Text += "Név:" + f.ReadLine.ToString + NewLine
                    s2 = f.ReadLine
                    s3 = f.ReadLine
                    RTBkiir.Text += "Darab: " + s2.ToString + NewLine + "Egységár: " + s3.ToString + NewLine + "-------------------------------------" + NewLine + "Összesen: " + (s2 * s3).ToString + "HUF" + NewLine + NewLine + NewLine
                    osszeg += s2 * s3
                Case "2"
                    RTBkiir.Text += "Név:" + f.ReadLine.ToString + NewLine + "Cikkszám: " + f.ReadLine.ToString + NewLine
                    s3 = f.ReadLine
                    RTBkiir.Text += "Ár: " + s3.ToString + NewLine + "-------------------------------------" + NewLine + "Összesen: " + s3.ToString + "HUF" + NewLine + NewLine + NewLine
                    osszeg += s3
            End Select
        Next
        If (f.ReadLine = "0") Then
            ChBfizetett.Checked = False
        Else
            ChBfizetett.Checked = True
        End If
        TBosszeg.Text = osszeg.ToString + " HUF"
        TBosszido.Text = osszido.ToString + " óra"
        f.Close()
    End Sub

    Private Sub Bmentes_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bmentes.Click
        Dim f As New StreamReader("adatlapszerelo.txt")
        Dim s As String
        Dim db As Integer = 0

        TBsegedkiir.Text = ""

        TBsegedkiir.Text += f.ReadLine + NewLine + f.ReadLine + NewLine
        s = f.ReadLine
        While s <> CBnev.SelectedItem
            TBsegedkiir.Text += s + NewLine
            s = f.ReadLine()
        End While

        TBsegedkiir.Text += s + NewLine
        For i As Integer = 1 To 5
            TBsegedkiir.Text += f.ReadLine() + NewLine
        Next

        db = f.ReadLine()
        TBsegedkiir.Text += db.ToString + NewLine
        For i As Integer = 1 To db * 4
            TBsegedkiir.Text += f.ReadLine + NewLine
        Next
        f.ReadLine()
        If (ChBfizetett.Checked) Then
            db = 1
        Else
            db = 0
        End If
        TBsegedkiir.Text += db.ToString + NewLine
        While Not f.EndOfStream 
            TBsegedkiir.Text += f.ReadLine() + NewLine
        End While
        f.Close()

        Dim fki As New StreamWriter("adatlapszerelo.txt")
        fki.Write(TBsegedkiir.Text)
        fki.Close()


        f = New StreamReader("adatlapnev.txt")

        TBsegedkiir.Text = ""
        s = f.ReadLine()
        While s <> CBnev.SelectedItem
            TBsegedkiir.Text += s.ToString + NewLine
            s = f.ReadLine()
        End While

        TBsegedkiir.Text += s.ToString + NewLine
        For i As Integer = 1 To 7
            TBsegedkiir.Text += f.ReadLine + NewLine
        Next
        db = f.ReadLine()
        TBsegedkiir.Text += db.ToString + NewLine
        For i As Integer = 1 To db * 4
            TBsegedkiir.Text += f.ReadLine + NewLine
        Next
        f.ReadLine()
        If ChBfizetett.Checked Then
            TBsegedkiir.Text += "1" + NewLine
        Else
            TBsegedkiir.Text += "0" + NewLine
        End If

        While Not f.EndOfStream
            TBsegedkiir.Text += f.ReadLine + NewLine
        End While

        f.Close()

        fki = New StreamWriter("adatlapnev.txt")
        fki.Write(TBsegedkiir.Text)
        fki.Close()

        f = New StreamReader("adatlapfelvetel.txt")
        TBsegedkiir.Text = ""
        TBsegedkiir.Text += f.ReadLine + NewLine + f.ReadLine + NewLine
        s = f.ReadLine
        While s <> CBnev.SelectedItem
            TBsegedkiir.Text += s + NewLine
            s = f.ReadLine()
        End While

        TBsegedkiir.Text += s + NewLine
        For i As Integer = 1 To 5
            TBsegedkiir.Text += f.ReadLine() + NewLine
        Next

        db = f.ReadLine()
        TBsegedkiir.Text += db.ToString + NewLine
        For i As Integer = 1 To db * 4
            TBsegedkiir.Text += f.ReadLine + NewLine
        Next
        f.ReadLine()
        If (ChBfizetett.Checked) Then
            db = 1
        Else
            db = 0
        End If
        TBsegedkiir.Text += db.ToString + NewLine
        While Not f.EndOfStream
            TBsegedkiir.Text += f.ReadLine() + NewLine
        End While

        f.Close()

        fki = New StreamWriter("adatlapfelvetel.txt")
        fki.Write(TBsegedkiir.Text)
        fki.Close()

        MsgBox("Sikeres mentés!", MsgBoxStyle.Information, "Siker")
    End Sub

    Private Sub MentésFájlbaToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MentésFájlbaToolStripMenuItem.Click
        TBfajlbair.Text = ""
        TBfajlbair.Text += "Név: " + CBnev.SelectedItem + NewLine
        TBfajlbair.Text += "Kód: " + CBkod.SelectedItem + NewLine
        TBfajlbair.Text += "Szerelő: " + CBszerelo.SelectedItem + NewLine
        TBfajlbair.Text += "Felvétel időpontja: " + CBdatum.SelectedItem + NewLine
        TBfajlbair.Text += "Lakcím: " + CBlakcim.SelectedItem + NewLine
        TBfajlbair.Text += "Telefonszám: " + CBtelefon.SelectedItem + NewLine
        TBfajlbair.Text += "Rendszám: " + CBrendszam.SelectedItem + NewLine
        TBfajlbair.Text += "Gépjármű típusa: " + CBtipus.SelectedItem + NewLine
        TBfajlbair.Text += "Kifizetve: "
        If ChBfizetett.Checked Then
            TBfajlbair.Text += "Igen" + NewLine + NewLine + NewLine
        Else
            TBfajlbair.Text += "Nem" + NewLine + NewLine + NewLine
        End If
        TBfajlbair.Text += RTBkiir.Text + NewLine + NewLine + NewLine + "----------------------------------------" + NewLine + NewLine
        TBfajlbair.Text += "Összesen: " + TBosszeg.Text + NewLine
        TBfajlbair.Text += "Várható munkaóra: " + TBosszido.Text + NewLine
        SaveFileDialog1.ShowDialog()
    End Sub

    Private Sub SaveFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles SaveFileDialog1.FileOk
        Dim SaveFile As String = SaveFileDialog1.FileName
        Dim objwriter As New StreamWriter(SaveFile)
        objwriter.Write(TBfajlbair.Text)
        objwriter.Close()
        MsgBox("Sikeres mentés!", MsgBoxStyle.Information, "Siker")
    End Sub

    Private Sub Btorol_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btorol.Click
        If Not ChBfizetett.Checked Then
            MsgBox("Nincs kifizetve a szerelés!", MsgBoxStyle.Critical, "Hiba")
        Else
            TBsegedkiir.Text = ""
            Dim f As New StreamReader("adatlapnev.txt")
            Dim s As String
            s = f.ReadLine
            While CBnev.SelectedItem <> s
                TBsegedkiir.Text += s + NewLine
                s = f.ReadLine
            End While
            For i As Integer = 1 To 7
                f.ReadLine()
            Next
            Dim db As Integer
            db = f.ReadLine()
            For i As Integer = 1 To ((db * 4) + 1)
                f.ReadLine()
            Next

            While Not f.EndOfStream
                TBsegedkiir.Text += f.ReadLine + NewLine
            End While
            f.Close()

            Dim fki As New StreamWriter("adatlapnev.txt")
            fki.Write(TBsegedkiir.Text)
            fki.Close()

            TBsegedkiir.Text = ""
            f = New StreamReader("adatlapszerelo.txt")
            Dim s1, s2 As String

            s1 = f.ReadLine()
            s2 = f.ReadLine()
            s = f.ReadLine()

            While s <> CBnev.SelectedItem

                TBsegedkiir.Text += s1 + NewLine + s2 + NewLine
                TBsegedkiir.Text += s + NewLine
                For i As Integer = 1 To 5
                    TBsegedkiir.Text += f.ReadLine + NewLine
                Next
                db = f.ReadLine
                TBsegedkiir.Text += db.ToString + NewLine
                For i As Integer = 1 To ((db * 4) + 1)
                    TBsegedkiir.Text += f.ReadLine() + NewLine
                Next
                s1 = f.ReadLine()
                s2 = f.ReadLine()
                s = f.ReadLine()
            End While

            For i As Integer = 1 To 5
                f.ReadLine()
            Next
            db = f.ReadLine()
            For i As Integer = 1 To ((db * 4) + 1)
                f.ReadLine()
            Next
            While Not f.EndOfStream
                TBsegedkiir.Text += f.ReadLine() + NewLine
            End While
            f.Close()

            fki = New StreamWriter("adatlapszerelo.txt")
            fki.Write(TBsegedkiir.Text)
            fki.Close()

            TBsegedkiir.Text = ""
            f = New StreamReader("adatlapfelvetel.txt")
            s1 = f.ReadLine()
            s2 = f.ReadLine()
            s = f.ReadLine()

            While s <> CBnev.SelectedItem

                TBsegedkiir.Text += s1 + NewLine + s2 + NewLine
                TBsegedkiir.Text += s + NewLine
                For i As Integer = 1 To 5
                    TBsegedkiir.Text += f.ReadLine + NewLine
                Next
                db = f.ReadLine
                TBsegedkiir.Text += db.ToString + NewLine
                For i As Integer = 1 To ((db * 4) + 1)
                    TBsegedkiir.Text += f.ReadLine() + NewLine
                Next
                s1 = f.ReadLine()
                s2 = f.ReadLine()
                s = f.ReadLine()
            End While

            For i As Integer = 1 To 5
                f.ReadLine()
            Next
            db = f.ReadLine()
            For i As Integer = 1 To ((db * 4) + 1)
                f.ReadLine()
            Next
            While Not f.EndOfStream
                TBsegedkiir.Text += f.ReadLine() + NewLine
            End While
            f.Close()

            fki = New StreamWriter("adatlapfelvetel.txt")
            fki.Write(TBsegedkiir.Text)
            fki.Close()

            MsgBox("Sikeres törlés!", MsgBoxStyle.Information, "Törlés")
            Close()
        End If
    End Sub
End Class